#include<iostream>
#include<fstream>
#include"1.pb.h"
using namespace std;
void PrintContact(contacts::Contacts&contacts)
{
    for(int i=0;i<contacts.contacts_size();i++)
    {
        cout<<"-------------联系人"<<i+1<<"---------------"<<endl;
        const contacts::PeopleInfo&people=contacts.contacts(i);
        cout<<"联系人姓名: "<<people.name()<<endl;
        cout<<"联系人年龄: "<<people.age()<<endl;
        for(int j=0;j<people.phone_size();j++)
        {
            const contacts::PeopleInfo_Phone& phone=people.phone(j);
            cout<<"联系人电话:"<<j+1<<phone.number();
            cout<<"  ("<<phone.PhoneType_Name(phone.type())<<')'<<endl;
        }
        if(people.has_data()&&people.data().Is<contacts::Address>())
        {
            contacts::Address address;
            people.data().UnpackTo(&address);
            if(!address.home_address().empty())
            {
                cout<<"联系人家庭地址： "<<address.home_address()<<endl;
            }
            if(!address.unit_address().empty())
            {
                cout<<"联系人单位地址： "<<address.unit_address()<<endl;
            }
        }
    }
}
int main() 
{
    contacts::Contacts contacts;
    fstream input("1.bin",ios::in | ios::binary);
    if(!input)
    {
        cout<<"1.bin not find,create new file"<<endl;
    }
    else if(!contacts.ParseFromIstream(&input))
    {
        cerr<<"parse error!"<<endl;
        input.close();
        return -1;
    }
    PrintContact(contacts);
    return 0;
}